using Coding4Fun.Phone.Controls.Data;
using Microsoft.Phone.Tasks;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Coding4Fun.Phone.Controls
{
	public class AboutPersonItem : Control
	{
		private const string string_0 = "emailAddress";
		private const string string_1 = "website";
		private const string string_2 = "author";
		private const string string_3 = "http://";
		private const string string_4 = "https://";
		private const string string_5 = "www.twitter.com";
		private TextBlock textBlock_0;
		private TextBlock textBlock_1;
		private TextBlock textBlock_2;
		private string string_6;
		public static readonly DependencyProperty WebSiteDisplayProperty = DependencyProperty.Register("WebSiteDisplay", typeof(string), typeof(AboutPersonItem), new PropertyMetadata(""));
		public static readonly DependencyProperty RoleProperty = DependencyProperty.Register("Role", typeof(string), typeof(AboutPersonItem), new PropertyMetadata(""));
		public static readonly DependencyProperty EmailAddressProperty = DependencyProperty.Register("EmailAddress", typeof(string), typeof(AboutPersonItem), new PropertyMetadata(""));
		public static readonly DependencyProperty AuthorNameProperty = DependencyProperty.Register("AuthorName", typeof(string), typeof(AboutPersonItem), new PropertyMetadata(""));
		public string WebSiteUrl
		{
			get
			{
				return this.string_6;
			}
			set
			{
				this.string_6 = value;
				this.WebSiteDisplay = value;
				AboutPersonItem.smethod_0(this.textBlock_1);
			}
		}
		protected internal string WebSiteDisplay
		{
			get
			{
				return (string)base.GetValue(AboutPersonItem.WebSiteDisplayProperty);
			}
			set
			{
				if (value != null)
				{
					value = value.ToLowerInvariant().TrimEnd(new char[]
					{
						'/'
					});
					if (value.StartsWith("https://"))
					{
						value = value.Remove(0, "https://".get_Length());
					}
					if (value.StartsWith("http://"))
					{
						value = value.Remove(0, "http://".get_Length());
					}
					if (!string.IsNullOrEmpty(value) && value.StartsWith("www.twitter.com"))
					{
						value = "@" + value.Remove(0, "www.twitter.com".get_Length()).TrimStart(new char[]
						{
							'/'
						});
					}
				}
				base.SetValue(AboutPersonItem.WebSiteDisplayProperty, value);
			}
		}
		public string Role
		{
			get
			{
				return (string)base.GetValue(AboutPersonItem.RoleProperty);
			}
			set
			{
				if (value != null)
				{
					value = value.ToLowerInvariant();
				}
				base.SetValue(AboutPersonItem.RoleProperty, value);
			}
		}
		public string EmailAddress
		{
			get
			{
				return (string)base.GetValue(AboutPersonItem.EmailAddressProperty);
			}
			set
			{
				if (value != null)
				{
					value = value.ToLowerInvariant();
				}
				base.SetValue(AboutPersonItem.EmailAddressProperty, value);
				AboutPersonItem.smethod_0(this.textBlock_0);
			}
		}
		public string AuthorName
		{
			get
			{
				return (string)base.GetValue(AboutPersonItem.AuthorNameProperty);
			}
			set
			{
				if (value != null)
				{
					value = value.ToLowerInvariant();
				}
				base.SetValue(AboutPersonItem.AuthorNameProperty, value);
				AboutPersonItem.smethod_0(this.textBlock_2);
			}
		}
		public AboutPersonItem()
		{
			base.set_DefaultStyleKey(typeof(AboutPersonItem));
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			if (this.textBlock_1 != null)
			{
				this.textBlock_1.remove_ManipulationCompleted(new EventHandler<ManipulationCompletedEventArgs>(this.websiteClick_ManipulationCompleted));
			}
			if (this.textBlock_0 != null)
			{
				this.textBlock_0.remove_ManipulationCompleted(new EventHandler<ManipulationCompletedEventArgs>(this.email_ManipulationCompleted));
			}
			this.textBlock_0 = (base.GetTemplateChild("emailAddress") as TextBlock);
			this.textBlock_1 = (base.GetTemplateChild("website") as TextBlock);
			this.textBlock_2 = (base.GetTemplateChild("author") as TextBlock);
			AboutPersonItem.smethod_0(this.textBlock_0);
			AboutPersonItem.smethod_0(this.textBlock_1);
			AboutPersonItem.smethod_0(this.textBlock_2);
			if (this.textBlock_0 != null)
			{
				this.textBlock_0.add_ManipulationCompleted(new EventHandler<ManipulationCompletedEventArgs>(this.email_ManipulationCompleted));
			}
			if (this.textBlock_1 != null)
			{
				this.textBlock_1.add_ManipulationCompleted(new EventHandler<ManipulationCompletedEventArgs>(this.websiteClick_ManipulationCompleted));
			}
		}
		private static void smethod_0(TextBlock textBlock_3)
		{
			if (textBlock_3 != null)
			{
				textBlock_3.set_Visibility(string.IsNullOrEmpty(textBlock_3.get_Text()) ? 1 : 0);
			}
		}
		protected internal void email_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			EmailComposeTask emailComposeTask = new EmailComposeTask();
			emailComposeTask.set_To(this.EmailAddress);
			emailComposeTask.set_Subject(PhoneHelper.GetAppAttribute("Title") + " Feedback");
			EmailComposeTask emailComposeTask2 = emailComposeTask;
			emailComposeTask2.Show();
		}
		protected internal void websiteClick_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			AboutPersonItem.smethod_1(this.WebSiteUrl);
		}
		private static void smethod_1(string string_7)
		{
			WebBrowserTask webBrowserTask = new WebBrowserTask();
			webBrowserTask.set_Uri(new Uri(string_7));
			WebBrowserTask webBrowserTask2 = webBrowserTask;
			webBrowserTask2.Show();
		}
	}
}
